package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.LabelItemsService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.LabelItemsAddVO;
import com.junzhiit.nengji.cms.web.vo.LabelItemsEditVO;
import com.junzhiit.nengji.cms.web.vo.LabelItemsListVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/label/items")
public class LabelItemsController extends BaseController{

	@Autowired
	private LabelItemsService labelItemsService;
	
	@ApiOperation(value="查询所有")
	@RequestMapping(method=RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp,LabelItemsListVO labelItemsListVO){
		return labelItemsService.findAll(dtp, labelItemsListVO);
	}
	
	@ApiOperation(value="查询id")
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResultVO findById(@PathVariable String id){
		AssertUtil.notBlank(id, "id is required");
		return labelItemsService.findById(id);
	}
	
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(LabelItemsAddVO labelItemsAddVO){
		AssertUtil.notBlank(labelItemsAddVO.getValue(), "value is required");
		AssertUtil.notBlank(labelItemsAddVO.getLabelId(), "labelId is required");
		return labelItemsService.add(labelItemsAddVO);
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.PUT)
	public ResultVO edit(@PathVariable String id,LabelItemsEditVO labelItemsEditVO){
		AssertUtil.notBlank(labelItemsEditVO.getValue(), "value is required");
		AssertUtil.notBlank(id, "id is required");
		return labelItemsService.edit(id,labelItemsEditVO);
	}
	
	
	@RequestMapping(value="/delete/{id}",method=RequestMethod.PUT)
	public ResultVO updateTodelete(@PathVariable String id){
		return labelItemsService.updateTodelete(id);
	}
	
	
}
